def prost(n):
    if len(str(n)) != 3:
        return False
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

tacx = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9
}

n = input().split()

if len(n) != 3 or not (set(n) <= set(tacx.keys())):
    print("Wrong input")
    exit()

n = tacx[n[0]] * 100 + tacx[n[1]] * 10 + tacx[n[2]]

if prost(n):
    print(n)
else:
    pright = n
    while not prost(pright):
        pright += 1

    pleft = n
    while not prost(pleft):
        pleft -= 1

    if abs(n - pright) <= abs(n - pleft):
        print(pright)
    else:
        print(pleft)